from threading import Thread
import time


def func():
    print("子线程要执行的任务代码")


class MyThread(Thread):
    def __init__(self, name, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.name = name

    def run(self):
        """run里面编写线程运行时要执行的任务代码"""
        print(f"{self.name}线程运行前!")
        super().run()
        print(f"{self.name}线程运行后!")


if __name__ == '__main__':
    t = MyThread(name="1号", target=func)
    t.start()
